package Demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Test4 {
    public static void main(String[] args) {
        Student2 s1 = new Student2("a", 12);
        Student2 s2 = new Student2("b", 14);

        ArrayList<Student2> list = new ArrayList<>();
        Collections.addAll(list, s1, s2);

        String[] arr = list.stream()
                .map(Student2::getNameAge)
                .toArray(String[]::new);

        System.out.println(Arrays.toString(arr));
    }
}

class Student2 {
    private String name;
    private int age;

    public Student2() {
    }

    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getNameAge() {
        return name + "-" + age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Student2{name = " + name + ", age = " + age + "}";
    }
}